package com.problem.leetcode;

/**
 * Given a 32-bit signed integer, reverse digits of an integer.
 * https://leetcode.com/problems/reverse-integer/description/
 *
 * @author yangzhuoleo
 * @Description ${Description}
 * @create 2018-01-02 22:47
 **/
public class Problem7 {
    public static void main(String[] args) {
        // int result = reverse(9646324351);
        // System.out.println(result);
    }

    public static int reverse(int x) {
        int rev = 0;
        while (x != 0) {
            if (rev != 0 && Integer.MAX_VALUE / rev < 10 && Integer.MAX_VALUE / rev > -10) {
                return 0;
            }
            rev = rev * 10 + x % 10;
            x = x / 10;
        }

        return rev;
    }

}
